package com.hdax.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 许可
 *
 * @author Aizen
 * @date 2022/05/07
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Component
public class Permission {
	private Integer id;
	/**
	 * 权限代码、user:create user:delete
	 */
	private String code;

	/**
	 * 权限类型、button link menu
	 */
	private String type;
	/**
	 * 权限名称
	 */
	private String name;
	/**
	 * 链接
	 */
	private String href;
	/**
	 * 图标
	 */
	private String icon;

	/**
	 * 父级 ID
	 */
	private Integer pid;

	/**
	 * 孩子们
	 */
	private List<Permission> children;


	private String title;
	private Boolean checked;
	private List<CheckArr> checkArr;
	private Integer parentId;

	/**
	 * 页面的tree节点默认展开
	 */
	private Boolean spread = true;

	public void setChecked(Boolean checked){
		CheckArr checkArr = new CheckArr();
		checkArr.setType("0");
		checkArr.setChecked(checked?"1":"0");
		List<CheckArr> checkArrs = new ArrayList<>();
		checkArrs.add(checkArr);
		this.checkArr = checkArrs;
	}

	@Data
	class CheckArr{
		private String checked;
		private String type;
	}



}
